package com.pj.wisdomlogistics.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.pj.wisdomlogistics.R;
import com.pj.wisdomlogistics.entity.DBLoginInfoObj;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseAdapter;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseViewHolder;
import com.zhy.autolayout.utils.AutoUtils;

/**
 * Created by WuFan on 2017/9/28.
 */

public class UserHisAdapter extends BaseAdapter<DBLoginInfoObj, BaseViewHolder> {
    public UserHisAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder createCustomViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(parent , R.layout.item_user);
    }

    @Override
    public void bindCustomViewHolder(final BaseViewHolder viewHolder, final int position) {
        AutoUtils.auto(viewHolder.itemView);

        final DBLoginInfoObj item = getItem(position);

        viewHolder.getTextView(R.id.tv_username).setText(item.getUsername());

        viewHolder.getTextView(R.id.tv_username).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mItemClick.chooseClick(position);
            }
        });

        viewHolder.getImageView(R.id.iv_delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mItemClick.deleteClick(position);
            }
        });
    }

    @Override
    public int getCustomViewType(int position) {
        return 0;
    }

    public itemClick mItemClick;

    public interface itemClick{
        void deleteClick(int id);
        void chooseClick(int id);
    }

    public void setListener(itemClick mListener){
        this.mItemClick = mListener;
    }
}
